package com.wisely.xxboot.domain;

import org.codehaus.jettison.json.JSONObject;

import java.text.DecimalFormat;
import java.util.Iterator;

/**
 * <p>Description:</p>
 * <p>Copyright: Copyright (c) 2017</p>
 * <p>Company: 中视数讯</p>
 * <p>Site: www.digi-zones.com</p>
 *
 * @author shengping
 * @version 1.0
 * @date 2017/7/3
 */
public class PriceCheap {

    public static void main(String[] args) throws Exception {
        JSONObject old = new JSONObject();
        old.put("wang:别走出这一步", 33.8);
        old.put("wang:外婆的道歉信", 31.2);
        old.put("wang:能断，给你强大", 23.8);
        old.put("wang:中产阶级", 33.9);
        old.put("wang:没什么了不起", 30.9);
        old.put("wang:愿你成为最好的女子", 25.1);
        old.put("sheng:步履不停", 26.00);
        old.put("sheng:极简主义", 26.6);
        old.put("sheng:你的善良必须有锋芒", 20.3);
        old.put("jiang:美国众神", 50.3);

        float price = 180.63f;

        System.out.println("先核对总价信息【原价】：");
        Iterator iterator = old.keys();
        float old_zongjia = 0f;
        while (iterator.hasNext()) {
            String key = (String) iterator.next();
            float sim_price = Float.valueOf(old.getString(key));
            System.out.println(key + "：" + sim_price + "元");
            old_zongjia = old_zongjia + Float.valueOf(old.getString(key));
        }
        System.out.println("先核对总价信息：" + old_zongjia + "【订单没折扣总价为：301.9元】");
        System.out.println("满减加券：减去121.27元后总支付为：180.63");
        DecimalFormat df = new DecimalFormat("######0.00000");
        float zhekou = Float.valueOf(df.format(Double.valueOf(180.63 / 301.9)));
        System.out.println("折扣：" + (Double.valueOf(180.63 / 301.9)) + "【保留五位小数】：" + zhekou);
        System.out.println("");
        System.out.println("每本书折扣后的价格：");
        float new_zongjia = 0f;
        Iterator iterator1 = old.keys();
        while (iterator1.hasNext()) {
            String key = (String) iterator1.next();
            float zk_price =  Float.valueOf(old.getString(key)) * zhekou;
            System.out.println(key + "：" + zk_price + "元");
            new_zongjia = new_zongjia + Float.valueOf(zk_price);
        }
        System.out.println("先核对总价信息：" + new_zongjia + "元，【订单没折扣总价为：180.63元】");
        System.out.println("");

        System.out.println("每人出的价格：");
        Iterator iterator2 = old.keys();
        float wang = 0f;
        float sheng = 0f;
        float jiang = 0f;
        while (iterator2.hasNext()) {
            String key = (String) iterator2.next();
            if(key.startsWith("wang")){
                float zk_price =  Float.valueOf(old.getString(key)) * zhekou;
                wang = wang + zk_price;
            }
            if(key.startsWith("sheng")){
                float zk_price =  Float.valueOf(old.getString(key)) * zhekou;
                sheng = sheng + zk_price;
            }
            if(key.startsWith("jiang")){
                float zk_price =  Float.valueOf(old.getString(key)) * zhekou;
                jiang = jiang + zk_price;
            }
        }
        System.out.println("wang："+wang + "元");
        System.out.println("sheng："+sheng + "元");
        System.out.println("jiang："+jiang + "元");
        System.out.println("合计："+(wang+sheng+jiang) + "元");
    }
}
